package servlet;

import dao.OrderDao;
import dao.factoty.DaoFactory;
import domain.Order;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet(name = "FindOrdersServlet", value = "/FindOrdersServlet")
public class FindOrdersServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        OrderDao orderDao = DaoFactory.getOrderDAOInstance();
        List<Order> orders = null;
        try{
            orders = orderDao.findAllOrder();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        request.setAttribute("orders", orders);
        request.getRequestDispatcher("/admin/login/home.jsp?item="+"orders").forward(request, response);
    }
}
